package Test;


/**
 * @author feng
 * @Date 2021/12/23 21:16
 */
public class Test07 {
    public static void main(String[] args) {
        int[] b = {1, 2, 4, 5, 15, 20, 25};    //3
        int[] a = {2, 4, 6, 10, 15}; //5
        int[] array = sumArray(a, b);
        for (int i : array) {
            System.out.println(i + "\t");
        }

    }

    public static int[] sumArray(int[] a, int[] b) {
        int max = a.length > b.length ? a.length : b.length;
        int[] c = new int[max];
        int min = a.length < b.length ? a.length : b.length;
        //返回相等时候的下标
        int i;
        //计算相等的部分
        for (i = 0; i < min; i++) {
            c[i] = a[i] + b[i];
        }
        //计算未对照的部分
        if (a.length > min) {
            for (int j = i; j < a.length; j++) { // i<2
                c[j] = a[j];   //从
            }
        }
        if (b.length > min) {
            for (int j = i; j < b.length; j++) { // i<2
                c[j] = b[j];   //从
            }
        }

        return c;
    }
}
